package com.ostrich.module_community.recommend.adapter

import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Toolbar
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.databinding.DataBindingUtil
import com.blankj.utilcode.util.ScreenUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ostrich.module_community.R
import com.ostrich.module_community.attention.entity.AttentionEntity
import com.ostrich.module_community.databinding.CommunityItemCommunityViewBinding
import com.ostrich.module_community.recommend.entity.ReCommendEntity

/**
 * @Author : yaotianxue
 * @Time : On 2023/10/31 16:01
 * @Description : ReCommendAdapter
 */
class ReCommendAdapter(private val layoutResId: Int,
                       data: MutableList<ReCommendEntity>):BaseQuickAdapter<ReCommendEntity,BaseViewHolder>(layoutResId,data){
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        DataBindingUtil.bind<CommunityItemCommunityViewBinding>(viewHolder.itemView)
    }
    override fun convert(holder: BaseViewHolder, item: ReCommendEntity) {
        holder.getBinding<CommunityItemCommunityViewBinding>()?.viewModel = item
        holder.getBinding<CommunityItemCommunityViewBinding>()?.executePendingBindings()

        //动态设置ImageView的高度= （屏幕宽度/2）*（图片高度）/（图片宽度）
        //1:计算高度
        val imageViewWidth = ScreenUtils.getScreenWidth() / 2//（屏幕宽度/2）
        val width = item.data.content.data.width//（图片宽度）
        val height = item.data.content.data.height//（图片高度）
        val imageViewHeight = imageViewWidth*height/width //最终ImageView的高度

        //2：java代码动态设置
        val layoutParams = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT,imageViewHeight)
        holder.getView<ImageView>(R.id.iv_cover_bg).layoutParams = layoutParams



    }
}